package com.sf.dlb.mapper.dao;

import com.sf.dlb.jpa.model.UserInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * Created by tanjing on 2019/5/14.
 */
@Mapper
public interface UserInfoMapper {

    /**
     * 查询用户列表-条件查询
     */
    @Select("<script>" +
            "   SELECT * FROM user_info a LEFT JOIN user_real_info r ON a.user_id=r.user_id " +
            "   <where> " +
            "        a.del_flag='0'" +
            "       <if test=\"userId!='' and userId!=null\">" +
            "           AND a.user_id=#{userId}" +
            "       </if>" +
            "       <if test=\"mobile!='' and mobile!=null\">" +
            "           AND a.mobile=#{mobile}" +
            "       </if>" +
            "       <if test=\"name!='' and name!=null\">" +
            "           AND a.`name` LIKE '%${name}%'" +
            "       </if>" +
            "       <if test=\"realState!='' and realState!=null and realState!=1\">" +
            "           AND r.state=#{realState}" +
            "       </if>" +
            "       <if test=\"realState!='' and realState!=null and realState==1\">" +
            "            AND (r.state=#{realState} OR r.state='' or r.state IS NULL)" +
            "       </if>" +
            "   </where> " +
            "  ORDER BY a.create_date DESC " +
            "</script>")
    List<UserInfo> queryUserInfoList(@Param("userId") String userId,@Param("mobile") String mobile,@Param("name") String name,@Param("realState") String realState);
}
